package cn.com.dhcc.turbo.dao.registry;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;

import cn.com.dhcc.app.core.CM;
import cn.com.dhcc.app.core.dao.BaseDao;
import cn.com.dhcc.app.core.exception.DaoException;
import cn.com.dhcc.app.core.service.Log;
import cn.com.dhcc.app.core.service.Log.LOGTYPE;
import cn.com.dhcc.turbo.entity.registry.MonitorRule;
import cn.com.dhcc.turbo.entity.registry.wapper.MonitorRuleRowWapper;
/**
 * 规则信息dao
 * 
 * @日期：2014-6-12 下午4:36:23
 * @作者：张洪涛
 * @版权所有：东华软件
 * @版本：1.0
 */
@Repository
public class MonitorRuleDao extends BaseDao {
	@SuppressWarnings("deprecation")
	private static Logger logger = Log.getExistLogger(LOGTYPE.SAI);

	/**
	 * 获取规则列表
	 * 
	 * @return
	 * @throws DaoException
	 */
	public List<MonitorRule> list(String quotaId) throws DaoException {
		String msg = "";
		String sql = " select * "
							+"	  from " + SI_TABLE("turbo_monitor_rule")+"  t1 "
							+"	 where t1.sn in "
							+"	       (select regexp_substr(t2.rule_for_select, '[^,]+', 1, l) "
							+"	          from " + SI_TABLE("turbo_monitor_quota")+"  t2, "
							+"	               (select level l from  dual   connect by level <= 100) b "
							+"	         where l <= length(t2.rule_for_select) - "
							+"	               length(replace(t2.rule_for_select, ',')) + 1 "
							+"	           and t2.id = ?) "
							+"	 order by t1.sn";
		try {
			return CM.getDao().list("获取规则列表", sql, new MonitorRuleRowWapper(),
					new Object[] {quotaId});
		} catch (DaoException e) {
			msg = "获取规则列表失败";
			logger.error(msg, e);
			throw new DaoException(msg, e);
		}
	}
}
